package cn.wzy.service.impl;

import cn.wzy.mapper.CarOnlineAuditLogMapper;
import cn.wzy.pojo.CarOnlineAuditLog;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.CarOnlineAuditLogService;
import cn.wzy.vo.GoPageVo;
import cn.wzy.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * (CarOnlineAuditLog)表服务实现类
 *
 * @author makejava
 * @since 2023-01-24 10:49:09
 */
@Service
public class CarOnlineAuditLogServiceImpl extends ServiceImpl<CarOnlineAuditLogMapper, CarOnlineAuditLog> implements CarOnlineAuditLogService {

 public ResponseResult getCarOnlineAuditLogPage(GoPageVo goPageVo) {
        Page<CarOnlineAuditLog> page = new Page<>(goPageVo.getPageIndex(),goPageVo.getPageSize());
        LambdaQueryWrapper<CarOnlineAuditLog> queryWrapper = new LambdaQueryWrapper<>();
        if (goPageVo.getKeyword()!=null && !"".equals(goPageVo.getKeyword())){
            queryWrapper.like(CarOnlineAuditLog::getNote,goPageVo.getKeyword());
        }
        List<CarOnlineAuditLog> productTypes = page(page, queryWrapper).getRecords();
        PageVo pageVo = new PageVo(productTypes, page.getTotal(), goPageVo.getPageSize());
        return ResponseResult.okResult(pageVo);
    }

    @Override
    public ResponseResult saveCarOnlineAuditLog(CarOnlineAuditLog carOnlineAuditLog) {
        //        判断是否id存在，操作类型
        if (Objects.isNull(carOnlineAuditLog.getId())){
//            添加操作
            save(carOnlineAuditLog);
            return ResponseResult.okResult();
        }else {
//            修改操作
            updateById(carOnlineAuditLog);
            return ResponseResult.okResult();
        }
    }

    @Override
    public ResponseResult deleteCarOnlineAuditLog(Long id) {
        removeById(id);
        return ResponseResult.okResult();
    }

    @Override
    public ResponseResult deleteCarOnlineAuditLogList(List<Long> ids) {
       removeByIds(ids);
       return ResponseResult.okResult();
    }
     @Override
    public ResponseResult getCarOnlineAuditLog(Long id) {
       CarOnlineAuditLog carOnlineAuditLog = getById(id);
       return ResponseResult.okResult(carOnlineAuditLog);
    }
}

